<!-- 文章内容细节 -->
<template>
  <div class="container">
    <el-card class="box-card">
      <div class="clearfix" slot="header">
        <el-page-header @back="$router.back()" content="文章详细">
        </el-page-header>
      </div>
      <div class="my item">
        <img src="../../assets/pic.png" alt="pic" />
        <h2>{{ author.username }}</h2>
      </div>
      <el-row>
        <div class="item content">
          <el-col
            :xl="{ span: 11, offset: 2 }"
            :lg="{ span: 12, offset: 2 }"
            :md="{ span: 12, offset: 2 }"
            :xs="24"
            :sm="24"
          >
            <div v-highlight>
              <div v-html="article.content" class="detail"></div>
            </div>
          </el-col>
          <el-col
            :xl="{ span: 8, offset: 1 }"
            :lg="{ span: 8, offset: 1 }"
            :md="{ span: 8, offset: 1 }"
            :xs="24"
            :sm="24"
          >
            <rightNav />
          </el-col>
        </div>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import { getArticleById } from "../../api/article";
import rightNav from "../../components/rightNav.vue";
export default {
  name: "artcle-detail",
  data() {
    const defaultAuthor = {
      username: "",
      pic: null,
    };
    return {
      article: "",
      author: Object.assign({}, defaultAuthor),
    };
  },
  methods: {
    async getArticle(a_id) {
      const { data } = await getArticleById(a_id);
      if (data.status === 200) {
        this.article = data.data[0];
        this.author = data.data[0].author;
        console.log(this.article);
      }
    },
  },
  created() {
    let id = this.$route.params.id;
    this.getArticle(id);
  },
  components: {
    rightNav,
  },
};
</script>

<style lang="less" scoped>
.container {
  .box-card {
    width: 96%;
    margin: 10px auto;
  }
  .my {
    display: flex;
    height: 80px;
    line-height: 80px;
    border-bottom: 1px solid #ccc;
    align-items: center;
    padding: 0 15px;
    img {
      width: 60px;
      height: 60px;
      margin-right: 10px;
      border-radius: 50%;
    }
  }
  .content {
    .detail {
      font-size: 16px;
      line-height: 25px;
      /deep/li {
        font-family: "pingfang SC", "helvetica neue", arial, "hiragino sans gb",
          "microsoft yahei ui", "microsoft yahei", simsun, sans-serif !important;
      }
      /deep/img {
        width: 350px;
      }
      /deep/.hljs {
        width: 100%;
        padding: 5px;
        border-radius: 10px;
        box-shadow: 0 5px 10px #ccc;
        overflow: auto;
      }
    }
  }
}
</style>